

package com.dog.basics.admin.controller.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.common.AdminDogNewsAddDto;
import com.dog.basics.bean.dto.admin.common.AdminDogNewsEditDto;
import com.dog.basics.bean.dto.admin.common.AdminDogNewsFromDto;
import com.dog.basics.bean.vo.admin.common.AdminDogNewsVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.common.DogNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 消息通知
 *
 * @author cy code generator
 * @date 2021-03-18 10:26:54
 */
@RestController
@AllArgsConstructor
@RequestMapping("/admin/dognews")
@Api(value = "消息通知管理", tags = "消息通知管理")
public class DogNewsController {

    private final DogNewsService dogNewsService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param obj  消息通知
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "admin_dognews_view")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('admin_dognews_view')" )
    public R<IPage<AdminDogNewsVo>> getDogNewsPage(PageParam page, AdminDogNewsFromDto obj) {
        return R.ok(dogNewsService.getAdminPageList(page, obj));
    }


    /**
     * 通过id查询消息通知
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "admin_dognews_info")
    @GetMapping("/{id}")
     @PreAuthorize("@pms.hasPermission('admin_dognews_info')" )
    public R<AdminDogNewsVo> getById(@PathVariable("id") Long id) {
        return R.ok(dogNewsService.getAdminObjXq(id));
    }

    /**
     * 新增消息通知
     *
     * @param obj 消息通知
     * @return R
     */
    @ApiOperation(value = "新增消息通知", notes = "admin_dognews_add")
    @SysLog("新增消息通知")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('admin_dognews_add')")
    public R<Boolean> save(@Valid @RequestBody AdminDogNewsAddDto obj) {
        return R.ok(dogNewsService.saveAdminObj(obj));
    }

    /**
     * 修改消息通知
     *
     * @param obj 消息通知
     * @return R
     */
    @ApiOperation(value = "修改消息通知", notes = "admin_dognews_edit")
    @SysLog("修改消息通知")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('admin_dognews_edit')")
    public R<Boolean> updateById(@Valid @RequestBody AdminDogNewsEditDto obj) {
        return R.ok(dogNewsService.editAdminObj(obj));
    }

    /**
     * 通过id删除消息通知
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除消息通知", notes = "admin_dognews_del")
    @SysLog("通过id删除消息通知")
    @DeleteMapping("/{id}")
    @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "Long")
    @PreAuthorize("@pms.hasPermission('admin_dognews_del')")
    public R<Boolean> removeById(@PathVariable Long id) {
        return R.ok(dogNewsService.deleteObj(id));
    }

}
